package com.wsd.interceptor;

import com.wsd.common.utils.JwtUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

/**
 * 权限拦截器
 */
@Component
public class AuthenticationInterceptor implements HandlerInterceptor {

    @Resource
    private JwtUtils jwtUtils;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        System.err.println("拦截到了: " + request.getRequestURI());
        String token = request.getHeader("Authorization");

        System.err.println(token);

        if (Objects.isNull(token) || token.isEmpty()) {
            System.err.println("用户没有权限，记得修改com.wsd.interceptor.AuthenticationInterceptor");
            // todo cancel the notes
//            throw new AuthenticationException();
        }

//        Claims claimByToken = jwtUtils.getClaimByToken(token);

        return true;
    }
}
